package com.hyh.toyshopping.service.impl;


import com.hyh.toyshopping.exceptions.PasswordException;
import com.hyh.toyshopping.exceptions.UsernameNotFoundException;
import com.hyh.toyshopping.mapper.AdminMapper;
import com.hyh.toyshopping.model.Admin;
import com.hyh.toyshopping.model.param.LoginParam;
import com.hyh.toyshopping.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:com.hyh.myshopping.service.Impl
 * @Author:hyhWTX
 * @ClassName:AdminServiceImpl
 * @CreateTime:2022年-12月-14日 21:01
 * @Description: TODO (一句话描述以下该类的功能)
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin login(LoginParam loginParam) {
        //根据用户名获得用户信息
        Admin admin = adminMapper.getAdminByName(loginParam.getUsername());
        //判断用户名是否正确
        if(admin == null){
            //使用异常处理用户名不存在
            throw new UsernameNotFoundException();
        }

        //判断密码是否正确
        if(!admin.getAdmin_password().equals(loginParam.getPassword())){
            //使用异常处理密码错误
            throw new PasswordException();
        }
        admin.setAdmin_password(null);
        return admin;
    }
}

